<template>
	<view>
	<u-navbar back-text="管理员注册学生" :customBack="back" backIconColor="#fff" :backTextStyle="{'color':'#fff'}" :background="background"></u-navbar>
	<view class="content">
		<view class="title">学生账号注册</view>
		<u-form-item left-icon="account" label-width="120" prop="name">
			<u-input type="text" class="u-border-bottom u-m-b-20" v-model="user5.name" placeholder="请输入学生姓名" />
		</u-form-item>
		<u-form-item left-icon="hourglass" label-width="120" prop="idNumber">
			<u-input type="text" class="u-border-bottom u-m-b-20" v-model="user5.idNumber" placeholder="请输入身份证号" />
		</u-form-item>
		<u-form-item left-icon="home" label-width="120" prop="stuNumber">
			<u-input type="text" class="u-border-bottom u-m-b-20" v-model="user5.stuNumber" placeholder="请输入学生学号" />
		</u-form-item>
		<u-form-item left-icon="home" label-width="120" prop="age">
			<u-input type="text" class="u-border-bottom u-m-b-20" v-model="user5.age" placeholder="请输入学生年龄" />
		</u-form-item>
		<u-form-item left-icon="home" label-width="120" prop="major">
			<u-input type="text" class="u-border-bottom u-m-b-20" v-model="user5.major" placeholder="请输入学生专业" />
		</u-form-item>
		<u-form-item left-icon="lock" label-width="120" prop="pwd">
			<u-input type="password" class="u-border-bottom" v-model="user5.pwd" placeholder="请输入密码" />
		</u-form-item>
		<u-form-item left-icon="lock-fill" label-width="120" prop="pwd">
			<u-input type="password" class="u-border-bottom" v-model="user5.pwd1" placeholder="请再次输入密码" />
		</u-form-item>
		
		<button @click="submit()" :style="[inputStyle]" class="getCaptcha">注 册</button>
		
		<view @tap="toHome()" class="to-home">
		返回首页
		</view>
		
	</view>
	
	</view>
</template>

<script>
	export default {
		data() {
			return {
				background: {
					'background-image': 'linear-gradient(45deg, #2BC3C8, #84E7B9)'
				},
				user5:{
					stuNumber:"",
					name:"",
					idNumber:"",
					pwd:"",
					pwd1:"",
					age:"",
					major:""
				},
			}
		},
		onLoad() {
			
		},
		computed: {
			inputStyle() {
				let style = {};
				if(this.mobile) {
					style.color = "#fff";
					style.backgroundColor = '#2BC3C8';
				}
				return style;
			}
		},
		methods:{
			toHome(){
				uni.switchTab({
					url: "/pages/mine/index"
				})
			},
			twist(){
				uni.navigateTo({
					url:"/pages/login/chaxun"
				})
			},
			back(){
				this.$common.switchTabTo('/pages/index/index');
			},
			submit(){
				if(this.user5.name==""){
					uni.showToast({
						title: '名字必须填写',
						icon: 'none'
					});
					return 
				}else if(this.user5.idNumber==""){
					uni.showToast({
						title: '身份证号必须填写',
						icon: 'none'
					});
					return 
				}else if(this.user5.stuNumber==""){
					uni.showToast({
						title: '学号必须填写',
						icon: 'none'
					});
					return 
				}else if(this.user5.age==""){
					uni.showToast({
						title: '学号必须填写',
						icon: 'none'
					});
					return 
				}else if(this.user5.major==""){
					uni.showToast({
						title: '学号必须填写',
						icon: 'none'
					});
					return 
				}else if(this.user5.pwd==""){
					uni.showToast({
						title: '初始密码必须填写',
						icon: 'none'
					});
					return 
				}else if(this.user5.pwd1==""){
					uni.showToast({
						title: '请再次填写密码',
						icon: 'none'
					});
					return 
				}else if(this.user5.pwd!=this.user5.pwd1){
					uni.showToast({
						title: '再次填写密码不同',
						icon: 'none'
					});
					return 
				}else if(this.user5.pwd==this.user5.pwd1){
					uni.request({
					 	url:"http://192.168.137.139:8080/adminRegister",
						method:"POST",
						data:this.user5,
						success: (res) => {
						 if (res.data.code*1==200) {
							 try{
								 uni.setStorageSync('user5',res.data.result)
								 console.log("学生账号注册成功.....")
								 this.$u.toast('学生账号注册成功......')
								setTimeout(function(){
									uni.navigateBack()
								},1000);
								console.log("页面跳转")
								console.log(res)
							 }catch(e){
								this.$u.toast('身份信息格式异常')
							 }
						 } else{
							this.$u.toast('注册失败，请尝试更换用户名')
							console.log(res)
						 }
						}
					})
				}
		}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		margin: 80rpx 60rpx 30rpx 60rpx;
	
		.title {
			text-align: center;
			font-size: 60rpx;
			font-weight: 500;
			margin-bottom: 100rpx;
		}
	
		.getCaptcha {
			background-color: #A9FFDA;
			color: #FFFFFF;
			border: none;
			font-size: 30rpx;
			margin: 60rpx 0;
			
			&::after {
				border: none;
			}
		}
		.alternative {
			color: $u-tips-color;
			display: flex;
			justify-content: space-between;
			margin-top: 30rpx;
		}
	}
	.buttom {
		.loginType {
			display: flex;
			padding: 200rpx 150rpx 150rpx 150rpx;
			justify-content:space-between;
			
			.item {
				display: flex;
				flex-direction: column;
				align-items: center;
				color: $u-content-color;
				font-size: 28rpx;
			}
		}
		
		.hint {
			padding: 20rpx 40rpx;
			font-size: 20rpx;
			color: $u-tips-color;
			text-align: center;
			.link {
				color: $u-type-warning;
			}
		}
	}
</style>

